home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRDELM.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  103 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8.         extrn    sl_malloc:far
  9. ;
  10. ; strdelm- deletes characters from a string.
  11. ;
  12. ; inputs:
  13. ;
  14. ;    ES:DI- Points at the string to delete characters from.
  15. ;
  16. ;    CX-    Index into source string (ES:DI) to begin deletion.
  17. ;
  18. ;    AX-    Number of characters to delete.
  19. ;
  20. ; outputs:
  21. ;
  22. ;    ES:DI-    Points at new string on stack which is the image of the
  23. ;        source string minus the specified characters.
  24. ;
  25. ;    Carry=1 if memory allocation error, 0 if sufficient memory for the
  26. ;        new string.
  27. ;
  28. ;
  29.         public    sl_strdelm
  30. ;
  31. ;
  32. sl_strdelm    proc    far
  33.         push    es
  34.         push    di
  35.         push    si
  36.         push    ds
  37.         push    ax
  38.         push    bx
  39.         push    cx
  40.         mov    bx, ax            ;Save length
  41. ;
  42. ; Compute the length of the source string:
  43. ;
  44.         push    es
  45.         push    di
  46.         push    cx
  47.         mov    cx, 0ffffh
  48.         mov    al, 0
  49.     repne    scasb
  50.         neg    cx
  51.         sub    cx, bx            ;Compute length of new str.
  52.         jnc    DoAlloc            ;Too much to delete?
  53.         pop    cx            ;Use insertion point as
  54.         push    cx            ; the length.
  55. ;
  56. DoAlloc:    call    sl_malloc
  57.         jnc    GoodAlloc
  58.         add    sp, 6
  59.         pop    cx
  60.         pop    bx
  61.         pop    ax
  62.         pop    ds
  63.         pop    si
  64.         pop    di
  65.         pop    es
  66.         ret
  67. ;
  68. GoodAlloc:    pop    cx
  69.         pop    si
  70.         pop    ds
  71.         push    es            ;Save ptr to new string.
  72.         push    di
  73. Cpy1:        lodsb
  74.         stosb
  75.         cmp    al, 0
  76.         loopne    Cpy1
  77.         jz    DelDone
  78. Skp1:        mov    cx, bx            ;Get # chars to delete
  79. Skp2:        lodsb
  80.         cmp    al, 0
  81.         loopne    Skp2
  82.         jz    DelDone
  83. Cpy2:        lodsb
  84.         stosb
  85.         cmp    al, 0
  86.         jnz    Cpy2
  87. ;
  88. DelDone:    mov    byte ptr es:[di], 0
  89.         pop    di
  90.         pop    es
  91.         pop    cx
  92.         pop    bx
  93.         pop    ax
  94.         pop    ds
  95.         pop    si
  96.         add    sp, 4            ;Don't restore es:di
  97.         ret
  98. sl_strdelm    endp
  99. ;
  100. ;
  101. stdlib        ends
  102.         end
  103.